home *** CD-ROM | disk | FTP | other *** search
/ Inside Mac Games Volume 4 #1 & #2 / IMG 34 JanFeb 1996.iso / Shareware / TANK OFF II / Programmer's Notes next >
Text File  |  1995-12-08  |  6KB  |  128 lines

  1. 'PROGRAMMER'S NOTES (PICTure Animation)
  2. 'TANK-OFF II Copyright © 1995 Scotty Mooneyham. All rights reserved.
  3.  
  4. 'This game was written in FUTURE BASIC v1.02™ for the Macintosh™.
  5. 'All art was drawn in ClarisWorks™.
  6. 'This file is for those that may be interested in the animation displayed 
  7. 'by this game. I use 2 different routines, #1 for drawing the scenes and #2 for
  8. 'animating PICT resources.
  9.  
  10. 'Before we start, here are a few routines that are needed to initilialize the routines
  11. 'that actually draw and animate PICT resources:
  12.  
  13. DIM foreground&,background&,savebuffer&,Gdevice&
  14. DIM r.8                                           'global rectangle
  15. CALL GETGWORLD(foreground&,Gdevice&)              'get window's port
  16. CALL SETRECT(r,0,0,640,480)
  17. background& = FN getOffScrnGWorld&(@r)            'get memory for background buffer
  18. savebuffer& = FN getOffScrnGWorld&(@r)            'get memory for animateSavePict routine
  19.  
  20. WINDOW OFF                                        'turn off the Command window
  21. WINDOW #1, "untitled", (0,0)-(640,480), _dialogPlain
  22.  
  23. LOCAL MODE                                      
  24. LOCAL FN setThePort (thePort&)                    'direct graphics drawing to a specific port
  25.  gDev& = FN GETGWORLDDEVICE(thePort&)
  26.  CALL SETGWORLD(thePort&,0)             
  27. END FN
  28.  
  29. 'The 1st routine draws PICT resources onto an off-screen buffer and displays
  30. 'the whole thing with COPYBITS:
  31.  
  32. '       Draw desert scene, sun, player's tank, tank's turrent and treads/flowers...
  33. FN drawPict(143,30,0)                             ' draw background scene
  34. FN drawPict(176,80,30)                            ' draw sun
  35. FN drawPict(133,x0%-31,y0%)                       ' draw player's tank
  36. FN drawPict(134,78,270)                           ' draw tread/flower #1
  37. FN drawPict(155,x%-15,y%-118)                     ' draw tank's turrent
  38. FN copyBits (background&,foreground&,@r,@r)
  39.  
  40. 'The varibles x0%,y0%,x% and y% were used during development for 
  41. 'animation alignment and are not relative here...
  42. 'Here are the routines that are called:
  43.  
  44. LOCAL
  45. DIM rect.8
  46. LOCAL FN drawPict  (pictID,xx,yy)                    
  47.  myPICT& = FN GETPICTURE(pictID)                  'get handle to PICT resource
  48.  LONG IF myPICT&                                  'handle available?
  49.   FN setThePort(background&)                      'point to off-screen buffer
  50.   PICTURE (xx,yy), myPICT&                        'draw PICT
  51.   FN setThePort(foreground&)                      'point to visible screen
  52.  END IF
  53. END FN  
  54.  
  55. 'and
  56.  
  57. LOCAL MODE                                        'copy bitmap from offscreen to window
  58. DIM s.8
  59. DIM r.8
  60. LOCAL FN copyBits (offPort&,wndPort&,s;8,r;8)
  61.  locked = FN LOCKPIXELS(FN GETGWORLDPIXMAP(offPort&))
  62.  LONG IF locked
  63.   CALL COPYBITS(#offPort&+2,#wndPort&+2,s,r,_srcCopy,0)
  64.   CALL UNLOCKPIXELS(FN GETGWORLDPIXMAP(offPort&))
  65.  END IF
  66. END FN
  67.  
  68. 'The #1 method isn't used for the actual animation because it would be
  69. 'extremely slow (copying 640x480 = 307,200 pixels, using 256 colors).
  70. 'This routine is used to draw the background art while routine #2 (shown below)
  71. 'is used to animate a particular section of the screen:
  72.  
  73. LOCAL
  74. DIM rect.8
  75. LOCAL FN animateSavePict  (pictID,xx,yy,count,visLast)                    
  76.  myPICT& = FN GETPICTURE(pictID)
  77.  rect;8 = [myPICT&]+_picFrame
  78.  CALL OFFSETRECT(rect,xx,yy)
  79.  FN setThePort(savebuffer&)
  80.  FN copyBits (background&,savebuffer&,@rect,@rect)
  81.  FOR i=pictID TO pictID+count
  82.   myPICT& = FN GETPICTURE(i)
  83.   FN setThePort(background&)
  84.   FN copyBits (savebuffer&,background&,@rect,@rect)
  85.   FN setThePort(background&)
  86.   PICTURE (xx,yy), myPICT& 
  87.   FN setThePort(foreground&)
  88.   FN copyBits (background&,foreground&,@rect,@rect)
  89.  NEXT i
  90.  IF visLast>0 THEN FN copyBits (savebuffer&,foreground&,@rect,@rect)
  91. END FN
  92.  
  93. 'Now an explanation is in order, this is what "animateSavePict" does...
  94. '1.This routine expects a series of PICT resources, beginning at "pictID" with
  95. '       the number of PICTs to be animated in "count" (whereas count=0 would mean
  96. '       only 1 picture would be available)
  97. '2.Get rectangle of first PICT and COPYBITS that rectangle from "background&" to
  98. '       "savebuffer&". Draw PICT onto "background&" and then COPYBITS same
  99. '       rectangle from "background&" to "foreground&". This in-direct drawing and copying
  100. '       is needed because the PICTs that are being drawn are object-based. Needing
  101. '       less memory (allowing more PICTs) but  requiring more drawing time, which if
  102. '       drawn directly to "foreground&" would allow user to view PICT being drawn 
  103. '       polygon-by-polygon, which would ruin the animation effect.
  104. '       "savebuffer&" is being used to store the pre-drawn playfield so when we draw
  105. '       an animation PICT over that area we can restore it fast and easy for the next
  106. '       frame (PICT) of animation.
  107. '3."xx" and "yy" are the horizontal and vertical positions where the animation PICTs
  108. '       will be drawn.
  109. '4."visLast" is used to tell the routine whether or not it should restore the screen
  110. '       back to it's original state before "animateSavePict" was called.
  111. '       For example:
  112. '       ***When the enemy tank fires, it restores the screen to it's previous state...
  113. 'FN animateSavePict  (pictID,xx,yy,count,visLast***)
  114. FN animateSavePict  (187,161,105,6,1***)
  115. '       ***But the "miss" routine doesn't:   (when the sand flys up and leaves a hole)
  116. FN animateSavePict  (194,31,110,4,0***)
  117.  
  118. 'Better methods are available for animation, but these are the ones I used in
  119. 'TANK-OFF II. The hard part is having something to animate. I spent more time
  120. 'drawing in ClarisWorks™ (DRAWING MODE) than I did in FutureBasic™ programming.
  121.  
  122. 'I hope this has helped somebody and that you enjoy the game. If any of this has
  123. 'helped/entertained you please send $5 (with comments/questions) to:
  124. 'Scotty Mooneyham
  125. '3345 Old Kentucky Road West
  126. 'Mosheim, TN. 37818
  127.  
  128.